package ledger

import (
	"jlpay-sdk-go/pkg/jlpay/core"
	"jlpay-sdk-go/pkg/jlpay/models/ledger"
	"jlpay-sdk-go/pkg/jlpay/services"
)

// BalanceSplitService 余额分账服务
type BalanceSplitService struct {
	*services.BaseService
}

// NewBalanceSplitService 创建余额分账服务
func NewBalanceSplitService(config *core.Config) *BalanceSplitService {
	return &BalanceSplitService{
		BaseService: services.NewBaseService(config),
	}
}

// QueryBalance 余额查询
func (s *BalanceSplitService) QueryBalance(request *ledger.BalanceQueryRequest) (*ledger.BalanceQueryResponse, error) {
	response := ledger.NewBalanceQueryResponse()
	err := s.Post(request, response, "/open/ledger/balance/query")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// SplitBalance 余额分账
func (s *BalanceSplitService) SplitBalance(request *ledger.BalanceSplitRequest) (*ledger.BalanceSplitResponse, error) {
	response := ledger.NewBalanceSplitResponse()
	err := s.Post(request, response, "/open/ledger/balance/split")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// QueryBalanceSplit 余额分账查询
func (s *BalanceSplitService) QueryBalanceSplit(request *ledger.BalanceSplitQueryRequest) (*ledger.BalanceSplitQueryResponse, error) {
	response := ledger.NewBalanceSplitQueryResponse()
	err := s.Post(request, response, "/open/ledger/balance/split/query")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// RefundBalance 余额退款
func (s *BalanceSplitService) RefundBalance(request *ledger.BalanceRefundRequest) (*ledger.BalanceRefundResponse, error) {
	response := ledger.NewBalanceRefundResponse()
	err := s.Post(request, response, "/open/ledger/balance/refund")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// QueryBalanceRefund 余额退款查询
func (s *BalanceSplitService) QueryBalanceRefund(request *ledger.BalanceRefundQueryRequest) (*ledger.BalanceRefundQueryResponse, error) {
	response := ledger.NewBalanceRefundQueryResponse()
	err := s.Post(request, response, "/open/ledger/balance/refund/query")
	if err != nil {
		return nil, err
	}
	return response, nil
}
